<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>


    function isObjectValueEqual(a, b) {
        //取对象a和b的属性名
        var aProps = Object.getOwnPropertyNames(a);
        var bProps = Object.getOwnPropertyNames(b);
        //判断属性名的length是否一致
        if (aProps.length != bProps.length) {
            return false;
        }
        //循环取出属性名，再判断属性值是否一致
        for (var i = 0; i < aProps.length; i++) {
            var propName = aProps[i];
            if (a[propName] !== b[propName]) {
                return false;
            }
        }
        return true;
    }
    var obj1 = { name: "Benjamin", sex: "male" };
    var obj2 = { name: "Benjamin", sex: "male" };
    var obj3 = obj1;                                //obj1和ob3的指针指向了内存中的同一个地址



    function isEqual(obj1,obj2){
            if(!obj1 instanceof Object || !obj2 instanceof Object){/*  判断不是对象  */
                return obj1 === obj2;
            }
            if(Object.keys(obj1).length !== Object.keys(obj2).length){
                return false;
                //Object.keys() 返回一个由对象的自身可枚举属性(key值)组成的数组,判断键值个数是否相等
            }
            for(var attr in obj1){//逐个值进行判断
                if(obj1[attr] instanceof Object && obj2[attr] instanceof Object){
                    return isEqual(obj1[attr],obj2[attr]);   //如果值为对象再递归进行判断
                }else if(obj1[attr] !== obj2[attr]){
                    return false;
                }
            }
            return true;
        }
var obj1={name:'tom',age:{name:'1tt'}};
var obj2={name:'tom',age:{name:'1trt'}};
console.log(isEqual(obj1,obj2))




</script>